// PROGRAMA : SCRP110A (COPIA DO ORIGINAL)
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// IDENTIFICACAO CRIMINAL
// BIBLIOTECA : SISP
// CLIENTE : GEJUSPC - GERENCIA DE ESTADO DA JUSTICA, SEGURANCA
// PUBLICA E CIDADANIA / INSTITUTO DE IDENT.
// OBJETIVO : INCLUSAO DA FICHA DE INDICE CRIMINAL
// PROGRAMADOR: JOSE ANTONIO COELHO
// DATA : 29 DE JULHO DE 1997
// ALTERACAO : 04/11/1999 TELA E DATA (N6) PARA (N8)
// POR SOLON
// ALTERACAO
// FONETIZACAO DO NOME, NOME DA MAE, NOME DO PAI
// E ALCUNHAS DO ARQUIVO SIC-CADASTRO.
// AUTOR: CARLOS HENRIQUE DATA: 16/11/1998
// GERACAO AUTOMATICA PELO SISTEMA DO REG. GERAL
// AUTOR: SOLON MIRANDA DATA: 11/02/1999
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1100;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm120a;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1300;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp110aA;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp110aB;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp110aC;
import br.com.vti.sisp_sicrim.antigo.model.DidRg;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicNumero;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrp110a OBJETIVO : INCLUSAO DA FICHA DE INDICE CRIMINAL *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/scrp110a")
public class Scrp110a {
	// Views utilizadas
	SicCadastro criminalView = new SicCadastro();
	SicNumero numeroView = new SicNumero();
	DidRg vwdidrg = new DidRg();
	// Telas/relatorios utilizados
	Scrm1100 scrm1100;
	Scrm120a scrm120a;
	Scrm1300 scrm1300;
	Scrp110aA scrp110aA;
	Scrp110aB scrp110aB;
	Scrp110aC scrp110aC;
	// Includes utilizados
	Estla001 estla001 = new Estla001();
	// Areas globais / session
	Scrg001 scrg001;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Scrp110a scrp110aAnterior;
	String faseproc = "0";
	String mensagemInicial = "";

	// private String chave = "I";
	private String dmanas = "";
	private long jUltNum = 0;
	private String jMaeLimpa = "";
	// 1 #INFRACAO (C) INIT <(AD=IP)>
	private String jCrime = "";
	private int jInd1 = 0;
	private int jInd2 = 0;
	private static final String jDozeAster = "************";
	private long wrg = 0;
	private int var = 0;
	private String mod = "";
	private int vlt = 0;
	private String[] tabm = { "", "   ", "VEI", "CON", "MUL", "   ", "IPV", "ROU", "   ", "   ", "   ", "   ", "   ", "IDC", "ICR", "FUN", "   ", "   " };

	private Scrm1100 preMapas() {
		sessao.getScrg001().setWContadorw(0);
		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName().toUpperCase());
		sessao.getScrg001().setWFuncaow("*** INCLUSAO ***          ");

		scrm1100 = new Scrm1100(true, sessao);
		scrm120a = new Scrm120a(true, sessao);
		scrm1300 = new Scrm1300(true, sessao);
		scrp110aA = new Scrp110aA(true, sessao);
		scrp110aB = new Scrp110aB(true, sessao);
		scrp110aC = new Scrp110aC(true, sessao);

		scrm1100.setDataCorrente(UtilBean.obtemDataDia());
		scrm120a.setDataCorrente(UtilBean.obtemDataDia());
		scrm1300.setDataCorrente(UtilBean.obtemDataDia());

		// Par�grafo: rp1()
		return scrm1100;
	}

	public Scrp110a(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar(Scrm1100 scrm1100, Scrm120a scrm120a, Scrm1300 scrm1300, Scrp110aA scrp110aA, Scrp110aB scrp110aB, Scrp110aC scrp110aC) {
		try {
			main(scrm1100, scrm120a, scrm1300, scrp110aA, scrp110aB, scrp110aC);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Scrm1100 pscrm1100, Scrm120a pscrm120a, Scrm1300 pscrm1300, Scrp110aA pscrp110aA, Scrp110aB pscrp110aB, Scrp110aC pscrp110aC) throws Exception {
		if (pscrm1100 == null && pscrm120a == null && pscrm1300 == null && pscrp110aA == null && pscrp110aB == null && pscrp110aC == null) {
			primeiraVez = true;
			// scrm1100 = new Scrm1100 (primeiraVez);
			scrm1100 = preMapas();
			scrm1100.setNavegar("../scrp110a/executar");
			scrm1100.setMensagem(mensagemInicial);
			result.include("scrm1100", scrm1100);
			sessao.setAtributo("SCRP110A", this);
			scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pscrm1100, pscrm120a, pscrm1300, pscrp110aA, pscrp110aB, pscrp110aC);
		}
		// Repeat
		criminalView.wFunc = "INCLUSAO";

		switch (faseproc) {
		case "0": {
			scrm1100.receberTela(false, result);
			if (scrm1100.temMensagem) {
				result.include("scrm1100", scrm1100);
				sessao.setAtributo("SCRP110A", this);
				scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			criminalView.wLoop = 0;
			criminalView.wData_nasc = scrm1100.getDataNasc();
			sessao.getScrg001().setWVltw(6);
			criminalView.wChv = "*";

			if (!criminalView.wData_nasc.trim().equals("")) {
				scrm120a.setJdataNasc(scrm1100.getDataNasc());
			}
			if (scrm1100.getJregGeral() != 0) {
				scrm120a.setJregGeral(scrm1100.getJregGeral());
			}
			if (scrm1100.getJmae() != jDozeAster) {
				jMaeLimpa = scrm1100.getJmae();
			} else {
				jMaeLimpa = "";
			}
			scrm120a.setJmae(jMaeLimpa);
			if (!scrm1100.getJnomecompleto().trim().equals("")) {
				scrm120a.setJnomecompleto(scrm1100.getJnomeCompleto());
			}
			criminalView.wLoop += 1;
			criminalView.wOcorrencia = 1;

			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 0, 7, "A", scrm1100.getDedos(1, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 7, 7, "A", scrm1100.getDedos(2, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 14, 7, "A", scrm1100.getDedos(3, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 21, 7, "A", scrm1100.getDedos(4, 1));
			criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 28, 7, "A", scrm1100.getDedos(5, 1));

			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 0, 7, "A", scrm1100.getDedos(1, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 7, 7, "A", scrm1100.getDedos(2, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 14, 7, "A", scrm1100.getDedos(3, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 21, 7, "A", scrm1100.getDedos(4, 2));
			criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 28, 7, "A", scrm1100.getDedos(5, 2));

			// Par�grafo: fd33()
			if (criminalView.consultaRegEstadualGeral(scrm1100.getJregGeral())) {
				if (criminalView.registrosProcessados() > 0)
				// && S-MAOESQ = #MAO-ESQUERDA)
				{
					// dao.rollback();
					if (criminalView.getStatusReg() == 5) {
						scrm1100.enviarMensagem(null, "ESTA FICHA ESTA� EXCLUIDA - NAO PODE SER ALTERADA");
						result.include("scrm1100", scrm1100);
						sessao.setAtributo("SCRP110A", this);
						scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
						return;
					} else {
						scrm1100.enviarMensagem(null, "FICHA CRIMINAL JA� CADASTRADA - CONSULTE-A");
						result.include("scrm1100", scrm1100);
						sessao.setAtributo("SCRP110A", this);
						scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
						return;
					}
				}
			}

			if (criminalView.registrosProcessados() == 0) {
				// Par�grafo: fd34()
				if (!scrm1100.getDedos('*', '*').equals("") && criminalView.consultaMaoDireitaMaoEsquerda(
				// jMaoDireita,
				scrm1100.getDedos(1, 1), scrm1100.getDedos(2, 1), scrm1100.getDedos(3, 1), scrm1100.getDedos(4, 1), scrm1100.getDedos(5, 1),
				// jMaoEsquerda
				scrm1100.getDedos(1, 2), scrm1100.getDedos(2, 2), scrm1100.getDedos(3, 2), scrm1100.getDedos(4, 2), scrm1100.getDedos(5, 2))) {
					if (jCrime.trim().equals("")) {
						jCrime = "*";
						scrm1100.enviarMensagem(null, "Formula Datil. Ja�Cadastrada Anteriormente.Consulte-a ou- Tecle <ENTER> p/ Cont.");
						result.include("scrm1100", scrm1100);
						sessao.setAtributo("SCRP110A", this);
						scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
						return;
					}
				}

				if (scrm1100.getJregGeral() == 0) {
					scrm120a.setJregGeral(jUltNum);
				}

				faseproc = "1";
				result.include("scrm120a", scrm120a);
				sessao.setAtributo("SCRP110A", this);
				scrm120a.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
		}
		case "1": {
			scrm120a.receberTela(false, result);
			if (scrm120a.temMensagem) {
				result.include("scrm120a", scrm120a);
				sessao.setAtributo("SCRP110A", this);
				scrm120a.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			faseproc = "2";
			result.include("scrm1300", scrm1300);
			sessao.setAtributo("SCRP110A", this);
			scrm1300.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		case "2": {
			scrm1300.receberTela(false, result);
			if (scrm1300.temMensagem) {
				result.include("scrm1300", scrm1300);
				sessao.setAtributo("SCRP110A", this);
				scrm1300.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				Scrp110a scrp110a = new Scrp110a(result, sessao);
				scrp110a.executar(null, null, null, null, null, null);
				return;
			}

			criminalView.wData_atu = UtilBean.obtemDataCorrente();
			criminalView.wTempo = UtilBean.obtemHoraDia();
			// criminalView.wHora = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 0, 2));
			// criminalView.wMin = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 3, 2));
			// criminalView.wSeg = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 6, 2));
			// criminalView.wNse = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 9, 1));
			criminalView.wHora_atu = Integer.parseInt(UtilBean.obtemHoraDia());
			criminalView.wData_nasc0 = scrm120a.getJdataNasc();
			criminalView.wData_nasc00 = Integer.parseInt(UtilBean.subStr(scrm120a.getJdataNasc(), 4, 4)) * 10000 + Integer.parseInt(UtilBean.subStr(scrm120a.getJdataNasc(), 2, 2)) * 100 + Integer.parseInt(UtilBean.subStr(scrm120a.getJdataNasc(), 0, 2));
			criminalView.wDataRegistro0 = Integer.parseInt(UtilBean.subStr(scrm120a.getJdataregistro(), 4, 4)) * 10000 + Integer.parseInt(UtilBean.subStr(scrm120a.getJdataregistro(), 2, 2)) * 100 + Integer.parseInt(UtilBean.subStr(scrm120a.getJdataregistro(), 0, 2));

			if (scrm120a.getJmae().equals("*")) {
				scrm120a.setJmae(jDozeAster);
			}
			if (scrm120a.getJpai().equals("*") || scrm120a.getJpai().trim().equals("")) {
				scrm120a.setJpai(jDozeAster);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm120a.getJalcunha(jInd1).trim().equals("") || scrm120a.getJalcunha(jInd1).equals("*")) {
					scrm120a.setJalcunha(jInd1, jDozeAster);
				}
			}
			if (scrm120a.getJnomeanterior().trim().equals("") || scrm120a.getJnomeanterior().equals("*")) {
				scrm120a.setJnomeanterior(jDozeAster);
			}
			if (scrm120a.getJnaturalidade().equals("*")) {
				scrm120a.setJnaturalidade(jDozeAster);
			}
			if (scrm120a.getJdocapresentado().equals("*")) {
				scrm120a.setJdocapresentado(jDozeAster);
			}
			if (scrm120a.getJavrua().equals("*")) {
				scrm120a.setJavrua(jDozeAster);
			}
			if (scrm120a.getJbairro().equals("*")) {
				scrm120a.setJbairro(jDozeAster);
			}
			if (scrm120a.getJcomplemento().trim().equals("") || scrm120a.getJcomplemento().equals("*")) {
				scrm120a.setJcomplemento(jDozeAster);
			}
			if (scrm1300.getJsinais().equals("*")) {
				scrm1300.setJsinais(jDozeAster);
			}
			if (scrm1300.getJnomevitima().equals("*")) {
				scrm1300.setJnomevitima(jDozeAster);
			}
			if (Integer.parseInt(scrm120a.getJdataatuacao()) < 1) {
				scrm120a.setJdataatuacao("0");
			}
			if (scrm120a.getJnoautos() < 1) {
				scrm120a.setJnoautos(0);
			}
			if (scrm120a.getJnumero() < 1) {
				scrm120a.setJnumero(0);
			}
			if (scrm120a.getJnumdocapresentado() < 1) {
				scrm120a.setJnumdocapresentado(0);
			}
			if (scrm120a.getJcodmunnascimento() < 1) {
				scrm120a.setJcodmunnascimento(0);
			}
			if (scrm120a.getJufnascimento().trim().equals("")) {
				scrm120a.setJufnascimento("**");
			}
			if (scrm120a.getJcep() < 1) {
				scrm120a.setJcep(0);
			}
			if (scrm120a.getJmunendereco() < 1) {
				scrm120a.setJmunendereco(0);
			}
			if (scrm120a.getJufendereco().trim().equals("")) {
				scrm120a.setJufendereco("**");
			}
			if (scrm120a.getJprofissao().equals("*") || scrm120a.getJprofissao().trim().equals("")) {
				scrm120a.setJprofissao(jDozeAster);
			}
			if (scrm120a.getJorgaoexpuf().equals("*") || scrm120a.getJorgaoexpuf().trim().equals("")) {
				scrm120a.setJorgaoexpuf(jDozeAster);
			}
			criminalView.setPossuiMandatoAberto(scrm1100.getJpossuiMandatoPAberto());
			criminalView.setRegEstadualGeral(scrm120a.getJregGeral());
			criminalView.setRegFederalCi(scrm120a.getJidentidade());
			criminalView.setStatusReg(Integer.parseInt(scrm120a.getJstatus()));
			criminalView.setTipoReg("IN");
			criminalView.setNomeCompleto(scrm120a.getJnomecompleto());
			criminalView.setNomePai(scrm120a.getJpai());
			criminalView.setNomeMae(scrm120a.getJmae());
			criminalView.setDataNasc(criminalView.wData_nasc00);
			criminalView.setPolegarDireito(scrm1100.getDedos(1, 1));
			criminalView.setIndicadorDireito(scrm1100.getDedos(2, 1));
			criminalView.setMedioDireito(scrm1100.getDedos(3, 1));
			criminalView.setAnularDireito(scrm1100.getDedos(4, 1));
			criminalView.setMinimoDireito(scrm1100.getDedos(5, 1));
			criminalView.setPolegarEsquerdo(scrm1100.getDedos(1, 2));
			criminalView.setIndicadorEsquerdo(scrm1100.getDedos(2, 2));
			criminalView.setMedioEsquerdo(scrm1100.getDedos(3, 2));
			criminalView.setAnularEsquerdo(scrm1100.getDedos(4, 2));
			criminalView.setMinimoEsquerdo(scrm1100.getDedos(5, 2));
			criminalView.setDataDocAtu(criminalView.wData_atu);
			criminalView.setHoraAtu(criminalView.wHora_atu);
			criminalView.setMatriculaFuncAtu(sessao.getScrg001().getWMatriculaw());
			criminalView.setNomeDelegacia(scrm120a.getJdelegacia());
			criminalView.setMunicipioRegGeral(scrm120a.getJdescmunicipio());
			criminalView.setCodigoMunicipioRegGeral(scrm120a.getJmunicipio());
			criminalView.setUfRegEstadualGeral(scrm120a.getJufreggeral());
			criminalView.setDataReg(criminalView.wDataRegistro0);
			criminalView.setNumeroAutos(scrm120a.getJnoautos());
			criminalView.setDataAtuacao(UtilBean.inverteDataYYYYMMDD(scrm120a.getJdataatuacao()));
			criminalView.setNomeAnterior(scrm120a.getJnomeanterior());
			criminalView.setApelidoAlcunhas(scrm120a.getJalcunha());
			criminalView.setSexo(scrm120a.getJsexo());
			criminalView.setNaturalidade(scrm120a.getJnaturalidade());
			criminalView.setCodigoMunicipioNasc(scrm120a.getJcodmunnascimento());
			criminalView.setUfNaturalidade(scrm120a.getJufnascimento());
			criminalView.setDocumentoApresent(scrm120a.getJdocapresentado());
			criminalView.setNumDocumentoApresent(scrm120a.getJnumdocapresentado());
			criminalView.setOrgaoExpUfUfUf(scrm120a.getJorgaoexpuf());
			criminalView.setProfissao(scrm120a.getJprofissao());
			criminalView.setGrauInstrucao(scrm120a.getJinstrucao());
			criminalView.setAvRua(scrm120a.getJavrua());
			criminalView.setNumero(scrm120a.getJnumero());
			criminalView.setBairro(scrm120a.getJbairro());
			criminalView.setMunicipio(scrm120a.getJmunendereco());
			criminalView.setEstado(scrm120a.getJufendereco());
			criminalView.setCep(scrm120a.getJcep());
			criminalView.setComplemento(scrm120a.getJcomplemento());
			criminalView.setAltura(Integer.parseInt(scrm1300.getJaltura()));
			criminalView.setEstadoCivil(Integer.parseInt(scrm1300.getJestadocivil()));
			criminalView.setCodigoCutis(Integer.parseInt(scrm1300.getJcutis()));
			criminalView.setCodigoCorCabelo(Integer.parseInt(scrm1300.getJcorcabelo()));
			criminalView.setCodigoTipoCabelo(Integer.parseInt(scrm1300.getJtipocabelo()));
			criminalView.setCodigoCorOlhos(Integer.parseInt(scrm1300.getJcorolhos()));
			criminalView.setMarcaPartCicatTatuag(scrm1300.getJsinais());
			criminalView.setCompleicao(Integer.parseInt(scrm1300.getJcompleicao()));
			criminalView.setNomeVitima(scrm1300.getJnomevitima());
			criminalView.setMotivoPrisaoLei(scrm1300.getJmotivo());
			criminalView.setCpf(scrm120a.getJcpf());
			if (scrm1300.getJobservacoes(1).trim().equals("")) {
				if (criminalView.wChv.equals("*")) {
					criminalView.wChv = "";
					scrm1300.enviarMensagem("jobservacoes[1]", "Nenhuma ocorrencia foi informada.Se nao quiser- informar Tecle ENTER p/confirmar");
					result.include("scrm1300", scrm1300);
					sessao.setAtributo("SCRP110A", this);
					scrm1300.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
			}
			// gravaOcorrencias(pscrp110aA);
			criminalView.setObservacao(scrm1300.getJobservacoes());

			// Fonetizacao dos campos.
			funcoes.phonNome = scrm120a.getJnomecompleto();
			// Phonet phonet = new Phonet ();
			funcoes.phonet(funcoes.phonArea);
			criminalView.setNomeCompletoPhon(funcoes.phonComb, 1, 168);
			if (scrm120a.getJmae() != jDozeAster) {
				funcoes.phonNome = scrm120a.getJmae();
				// Phonet phonet = new Phonet ();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomeMaePhon(funcoes.phonComb, 1, 155);
			}
			if (scrm120a.getJpai() != jDozeAster) {
				funcoes.phonNome = scrm120a.getJpai();
				// Phonet phonet = new Phonet ();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomePaiPhon(funcoes.phonComb, 1, 150);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm120a.getJalcunha(jInd1) != jDozeAster) {
					funcoes.phonNome = scrm120a.getJalcunha(jInd1);
					// Phonet phonet = new Phonet ();
					funcoes.phonet(funcoes.phonArea);
					jInd2 = jInd1 * 42;
					criminalView.setApelidoAlcunhasPhon(funcoes.phonComb, 1, 42);
				}
			}

			if (scrm1300.getJconf().trim().equals("")) {
				scrm1300.enviarMensagem("jconf", "Confirme �S� ou �N�");
				result.include("scrm1300", scrm1300);
				sessao.setAtributo("SCRP110A", this);
				scrm1300.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (!(scrm1300.getJconf().trim().toUpperCase().equals("S") || scrm1300.getJconf().trim().toUpperCase().equals("N"))) {
				scrm1300.enviarMensagem("jconf", "Confirmacao invalida");
				result.include("scrm1300", scrm1300);
				sessao.setAtributo("SCRP110A", this);
				scrm1300.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrm1300.getJconf().trim().toUpperCase().equals("N")) {
				// dao.rollback();
				Scrp110a scrp110a = new Scrp110a(result, sessao);
				scrp110a.executar(null, null, null, null, null, null);
				return;
			} else {
				if (criminalView.wLoop == 1) {
					faseproc = "3";
					result.include("scrp110aC", scrp110aC);
					sessao.setAtributo("SCRP110A", this);
					scrp110aC.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				} else {
					ultimoRegistro();
					scrm1100.setMensagem("REGISTRO INCLUIDO COM SUCESSO - TECLE ENTER");
				}
			}
			break;
		}
		case "3": {
			scrp110aC.receberTela(false, result);
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				// dao.rollback();
				scrm1100.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE ENTER");
				result.include("scrm1100", scrm1100);
				sessao.setAtributo("SCRP110A", this);
				scrm1100.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrp110aC.getJmat() == 0) {
				scrp110aC.enviarMensagem("jmat", "INFORME A MATRICULA");
				result.include("scrp110aC", scrp110aC);
				sessao.setAtributo("SCRP110A", this);
				scrp110aC.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrp110aC.getJmat() != sessao.getScrg001().getWMatriculaw()) {
				scrp110aC.enviarMensagem("jmat", "MATRICULA NAO CORRESPONDE A MATRICULA INICIAL");
				result.include("scrp110aC", scrp110aC);
				sessao.setAtributo("SCRP110A", this);
				scrp110aC.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (scrp110aC.getJsenha().trim().equals("")) {
				scrp110aC.enviarMensagem("jsenha", "INFORME A SENHA");
				result.include("scrp110aC", scrp110aC);
				sessao.setAtributo("SCRP110A", this);
				scrp110aC.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (!scrp110aC.getJsenha().trim().equals(sessao.getScrg001().getWSenhaw())) {
				scrp110aC.enviarMensagem("jsenha", "SENHA NAO CORRESPONDE A SENHA INICIAL");
				result.include("scrp110aC", scrp110aC);
				sessao.setAtributo("SCRP110A", this);
				scrp110aC.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			ultimoRegistro();
			scrm1100.setMensagem("REGISTRO INCLUIDO COM SUCESSO - TECLE ENTER");
			faseproc = "0";
			// END TRANSACTION
		}

			// jVariaveis_da_tela = "";
			criminalView.wChave = "";
			criminalView.wText = "";
			jCrime = "";

			scrm1100.setJregGeral(wrg);
			scrm1100.setJdisprg("<== ULTIMO REGISTRO GRAVADO");
			sessao.setAtributo("SCRP110A", this);
			result.include("scrm1100", scrm1100);
			scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}
	}

	// RESET #VARIAVEIS #CHAVE
	private void gravaOcorrencias(Scrp110aA pscrp110aA) {
		int ind = 0;
		criminalView.wI = 1;
		if (!scrm1300.getJobservacoes(1).trim().equals(""))
		// SET KEY ALL
		{
			// if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) ||
			// UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
			// scrm1300.enviarMensagem(null, "Tecla invalida");
			// return;
			// }
			for (ind = 2; ind <= 40; ind++) {
				scrp110aA.setJocorrencia(ind);
				if (scrp110aA.getJocorrencia() == 2) {
					criminalView.wJ = scrp110aA.getJocorrencia();
					criminalView.wL = scrp110aA.getJocorrencia() + 1;
					criminalView.wM = scrp110aA.getJocorrencia() + 2;
				} else {
					criminalView.wI = criminalView.wM + 1;
					criminalView.wJ = criminalView.wM + 2;
					criminalView.wL = criminalView.wM + 3;
					criminalView.wM = criminalView.wM + 4;
				}

				criminalView.wObservacoez[criminalView.wI] = scrm1300.getJobservacoes(1);
				criminalView.wObservacoez[criminalView.wJ] = scrm1300.getJobservacoes(2);
				criminalView.wObservacoez[criminalView.wL] = scrm1300.getJobservacoes(3);
				criminalView.wObservacoez[criminalView.wM] = scrm1300.getJobservacoes(4);
				for (int i1 = 1; i1 <= 4; i1++) {
					criminalView.wObservacoes[i1] = "";
				}

				if (!scrp110aA.getEnviada()) // CONFIRMACAO
				{
					result.include("scrp110aA", scrp110aA);
					sessao.setAtributo("SCRP110A", this);
					scrp110aA.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (pscrp110aA != null) {
					scrp110aA.receberTela(false, result);
				}

				// 19/01 ' ' (77)
				// 20/01 ' ' (77)
				// 21/01 ' ' (77)
				// 22/01 ' ' (77)
				// 23/01 'PF3 - Retorna'

				if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
					scrp110aA.enviarMensagem(null, "Tecla invalida");
					result.include("scrp110aA", scrp110aA);
					sessao.setAtributo("SCRP110A", this);
					scrp110aA.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
					Scrp110a scrp110a = new Scrp110a(result, sessao);
					scrp110a.executar(null, null, null, null, null, null);
					return;
				}
				for (criminalView.wX = 4; criminalView.wX >= 2; criminalView.wX += -1) {
					if (!scrm1300.getJobservacoes(criminalView.wX).trim().equals("")) {
						criminalView.wW = criminalView.wX - 1;
						for (criminalView.wY = criminalView.wW; criminalView.wY >= 1; criminalView.wY += -1) {
							if (scrm1300.getJobservacoes(criminalView.wY).trim().equals("")) {
								scrm1300.enviarMensagem(null, "Existe espaco nas linhas acima das que voce informou");
								result.include("scrm1300", scrm1300);
								sessao.setAtributo("SCRP110A", this);
								scrm1300.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
								return;
							}
						}
					}
				}
				if (scrm1300.getJobservacoes(1).trim().equals("")) {
					break;
				}
			}
		}
	}

	private void verStatus() {
		switch (criminalView.wStatus0) {
		case 1: {
			scrm120a.setJdescreg("Registro Normal");
			break;
		}
		case 2: {
			scrm120a.setJdescreg("Registro Cancelado");
			break;
		}
		case 3: {
			scrm120a.setJdescreg("REGISTRO COM MANDATO DE PRISAO");
			break;
		}
		case 4: {
			scrm120a.setJdescreg("Condenado");
			break;
		}
		default: {
			break;
		}
		}
	}

	private void ultimoRegistro() {

		while (numeroView.leitura()) {
			numeroView.setUltimoNumero(numeroView.getUltimoNumero() + 1);
			wrg = numeroView.getUltimoNumero();
			numeroView.atualiza();
		}
		numeroView.fecha();

		criminalView.setRegEstadualGeral(wrg);
		criminalView.grava();
		criminalView.fecha();
		// dao.commit();
		// ATUALIZA DID-RG REGISTROS PARA ABN
		if (vwdidrg.consultaNumeroRg(scrm120a.getJregGeral())) {
			vwdidrg.setNumeroRg(scrm120a.getJregGeral());
			vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
			vwdidrg.setHoraAtualizacao(Integer.parseInt(UtilBean.obtemHoraDia()));
			// abnFlag = "";
			vwdidrg.atualiza();
		} else {
			vwdidrg.setNumeroRg(scrm120a.getJregGeral());
			vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
			vwdidrg.setHoraAtualizacao(Integer.parseInt(UtilBean.obtemHoraDia()));
			// abnFlag = "";
			vwdidrg.grava();
			// dao.commit();
		}
		vwdidrg.fecha();
		// ATUALIZA SIC-ESTATISTICAS NO CRIMINAL

		estla001.cpo = 01;
		estla001.qde = 01;
		// INCLUS�O
		sessao.getSisgsisp().setVlt(14);
		sessao.getSisgsisp().setVar(14);
		// QUANTIDADE
		mod = tabm[14];
		// ICR = MOD
		estla001.esttip = 98;
		// ICR
		funcoes.estna001(estla001.cpo, estla001.esttip, estla001.qde, var, sessao.getScrg001().getWMatriculaw());
	}

	private void restaurarEstados(Scrm1100 pscrm1100, Scrm120a pscrm120a, Scrm1300 pscrm1300, Scrp110aA pscrp110aA, Scrp110aB pscrp110aB, Scrp110aC pscrp110aC) {
		this.scrp110aAnterior = (Scrp110a) sessao.getAtributo("SCRP110A");
		if (pscrm1100 != null) {
			scrm1100 = pscrm1100;
			scrm1100.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm1100.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm1100.setJprogramaj(sessao.getScrg001().getWProgramaw());
			scrm1100.setJversaoj(sessao.getScrg001().getWVersaow());
		} else {
			scrm1100 = this.scrp110aAnterior.scrm1100;
		}
		scrm1100.setSessao(sessao);
		if (pscrm120a != null) {
			scrm120a = pscrm120a;
			scrm120a.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm120a.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm120a.setJprogramaj(sessao.getScrg001().getWProgramaw());
			scrm1100.setJversaoj(sessao.getScrg001().getWVersaow());
		} else {
			scrm120a = this.scrp110aAnterior.scrm120a;
		}
		scrm120a.setSessao(sessao);
		if (pscrm1300 != null) {
			scrm1300 = pscrm1300;
			scrm1300.setJfuncaoj(sessao.getScrg001().getWFuncaow());
			scrm1300.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm1300.setJprogramaj(sessao.getScrg001().getWProgramaw());
			scrm1100.setJversaoj(sessao.getScrg001().getWVersaow());
		} else {
			scrm1300 = this.scrp110aAnterior.scrm1300;
		}
		scrm1300.setSessao(sessao);
		if (pscrp110aA != null) {
			scrp110aA = pscrp110aA;
		} else {
			scrp110aA = this.scrp110aAnterior.scrp110aA;
		}
		scrp110aA.setSessao(sessao);
		if (pscrp110aB != null) {
			scrp110aB = pscrp110aB;
		} else {
			scrp110aB = this.scrp110aAnterior.scrp110aB;
		}
		scrp110aB.setSessao(sessao);
		if (pscrp110aC != null) {
			scrp110aC = pscrp110aC;
		} else {
			scrp110aC = this.scrp110aAnterior.scrp110aC;
		}
		scrp110aC.setSessao(sessao);
		this.faseproc = this.scrp110aAnterior.faseproc;
		this.criminalView = this.scrp110aAnterior.criminalView;
	}

	protected void setMensagem(String mensagem) {
		mensagemInicial = mensagem;
	}
}
